home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * This file contains the functions which initialize the core
- * AppleEvents for the program.
- **********************************************************************/
-
- #include "Creator Changer.h"
- #include "Creator Changer.AE.h"
- #include "GetFileIcon.h"
-
-
- /**********************************************************************
- * Function Install_AE_Handlers(), this function sets up the
- * AppleEvents for the program.
- **********************************************************************/
-
- void Install_AE_Handlers(void)
- {
-
- AEEventHandlerUPP open_ae, quit_ae, start_ae, print_ae;
-
- open_ae=NewAEEventHandlerProc(Open_AE);
- quit_ae=NewAEEventHandlerProc(Quit_AE);
- start_ae=NewAEEventHandlerProc(Start_AE);
- print_ae=NewAEEventHandlerProc(Print_AE);
-
- AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, open_ae, FALSE, FALSE);
- AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, quit_ae, FALSE, FALSE);
- AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, start_ae, FALSE, FALSE);
- AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, print_ae, FALSE, FALSE);
-
- }
-
-
-
- /**********************************************************************
- * Function Open_AE(), this function supports what happens when a file
- * is dropped on Creator Changer.
- **********************************************************************/
-
- pascal OSErr Open_AE(AppleEvent *the_event, AppleEvent *the_reply, long ref_con)
- {
-
- AEDescList the_files;
- AEKeyword key_word;
- DescType the_type;
- Size the_size;
- auto_chng **rsrc_handle;
- File_Union temp_text;
- Str4 types[100];
- short i, the_item=1;
- OSType file, creator;
- long num_of_files;
-
- AEGetParamDesc(the_event, keyDirectObject, typeAEList, &the_files);
- AECountItems(&the_files, &num_of_files);
-
- if((**Global).AutoChange && Control_Key_Down)
- {
- Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Num_ac);
- Get_Types_From_Prefs(types);
- for(i=1;i<=num_of_files;i++)
- {
- Multiple_Files=NO;
- AEGetNthPtr(&the_files, i, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
- FSpGetFInfo(&The_File_Spec, &File_Info);
- the_item=Check_File_Type(types, File_Info.fdType);
- if(the_item)
- {
- UseResFile(CreatorChangerPref);
- rsrc_handle=(auto_chng **)GetResource(PREF_AC, The_ac_Type[the_item]);
- Set_Long_Type((**rsrc_handle).ToFile, &File_Info.fdType, NIL_PTR, NIL_PTR);
- Set_Long_Type((**rsrc_handle).ToCreator, &File_Info.fdCreator, NIL_PTR, NIL_PTR);
- ReleaseResource((Handle)rsrc_handle);
- UseResFile(CreatorChangerApp);
- FSpSetFInfo(&The_File_Spec, &File_Info);
- Force_Finder_Update(&The_File_Spec);
- }
- else
- {
- GetFileIcon(&The_File_Spec, svAllAvailableData, &The_Icons);
- Open_DLOG(&Chng_Dialog, PREF_TYPES_ID, PREF_PT, CHNG_TYPE_DLOG_ID, Num_pt, Chng_Storage, &the_files, one_file);
- }
- }
- AEDisposeDesc(&the_files);
- }
- else
- {
- if(num_of_files==1)
- {
- Multiple_Files=NO;
- AEGetNthPtr(&the_files, 1, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
- FSpGetFInfo(&The_File_Spec, &File_Info);
- GetFileIcon(&The_File_Spec, svAllAvailableData, &The_Icons);
- AEDisposeDesc(&the_files);
- }
- else Multiple_Files=YES;
-
- Open_DLOG(&Chng_Dialog, PREF_TYPES_ID, PREF_PT, CHNG_TYPE_DLOG_ID, Num_pt, Chng_Storage, &the_files, num_of_files);
-
- Multiple_Files=NO;
- }
-
- if((**Global).DragQuit==TRUE) All_Done=TRUE;
-
- return(noErr);
-
- }
-
-
-
- /**********************************************************************
- * Function Get_Types_From_Prefs(), this function gets the types from
- * preference file and stores them in an array, for later use.
- **********************************************************************/
-
- void Get_Types_From_Prefs(Str4 *the_array)
- {
-
- short i;
- auto_chng **the_handle;
-
- UseResFile(CreatorChangerPref);
- the_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
- for(i=1;i<=Num_ac;i++)
- {
- the_handle=(auto_chng **)GetResource(PREF_AC, The_ac_Type[i]);
- p_Str_Copy((**the_handle).FromFile, the_array[i]);
- ReleaseResource((Handle)the_handle);
- }
- UseResFile(CreatorChangerApp);
-
- }
-
-
-
- /**********************************************************************
- * Function Check_File_Type(), this function checks the current file's
- * file type against those in the array created before.
- **********************************************************************/
-
- int Check_File_Type(Str4 *the_arry, OSType the_ostype)
- {
-
- short i;
- File_Union the_union_type;
-
- Set_Type_Text(&the_union_type, the_ostype);
-
- for(i=1;i<=Num_ac;i++) if(Comp_The_String(the_arry[i], the_union_type.TEXT)) return(i);
- return(BAD);
-
- }
-
-
-
- /**********************************************************************
- * Function Quit_AE(), this function supports the 'quit' event. All
- * that it does is set the global switch to true to quit.
- **********************************************************************/
-
- pascal OSErr Quit_AE(AppleEvent *theEvent, AppleEvent *reply, long ref_con)
- {
-
- All_Done=TRUE;
- return(noErr);
-
- }
-
-
-
- /**********************************************************************
- * Function Print_AE(), this function does nothing, besides report
- * that CC does not support the print event.
- **********************************************************************/
-
- pascal OSErr Print_AE(AppleEvent *theEvent, AppleEvent *reply, long ref_con)
- {
-
- return(errAEEventNotHandled);
-
- }
-
-
-
- /**********************************************************************
- * Function Start_AE(), this function controls what happens when
- * Creator Changer is launched.
- **********************************************************************/
-
- pascal OSErr Start_AE(AppleEvent *theEvent, AppleEvent *reply, long ref_con)
- {
-
- Handle_Options_Choice(O_OPEN_ITEM);
- return(noErr);
-
- }
-